package com.edu.glutdataconvertclient.service.impl;

import com.edu.glutdataconvertclient.mapper.auto.*;
import com.edu.glutdataconvertclient.service.AsyncService;
import com.edu.glutdataconvertclient.service.ViewService;
import com.edu.glutdataconvertcommon.domain.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author ares
 */
@Slf4j
@Service
public class ViewServiceImpl implements ViewService {

    private final static Integer limit = 1000;
    private TGlutDcJhkczlbMapper tGlutDcJhkczlbMapper;
    private TGlutDcJsjbsjzlbMapper tGlutDcJsjbsjzlbMapper;
    private TGlutDcJxhbxxMapper tGlutDcJxhbxxMapper;
    private TGlutDcKcsjlbMapper tGlutDcKcsjlbMapper;
    private TGlutDcKcsjlbXxxsMapper tGlutDcKcsjlbXxxsMapper;
    private TGlutDcKsapsjlbMapper tGlutDcKsapsjlbMapper;
    private TGlutDcSkjsxxMapper tGlutDcSkjsxxMapper;
    private TGlutDcXksjlbMapper tGlutDcXksjlbMapper;
    private TGlutDcZtjhzlbMapper tGlutDcZtjhzlbMapper;
    private TGlutDcZyxxsjlbMapper tGlutDcZyxxsjlbMapper;
    private TGlutDcXjjbsjzlbMapper tGlutDcXjjbsjzlbMapper;
    private TGlutDcXsjbsjzlMapper tGlutDcXsjbsjzlMapper;
    private TGlutDcBjsjlbMapper tGlutDcBjsjlbMapper;
    private TGlutDcJiankaoMapper tGlutDcJiankaoMapper;
    private TGlutDcKsbjMapper tGlutDcKsbjMapper;
    private TGlutDcKsMapper tGlutDcKsMapper;
    private TGlutDcZyjsBjMapper tGlutDcZyjsBjMapper;
    private TGlutDcZyjsKaoshengMapper tGlutDcZyjsKaoshengMapper;
    private TGlutDcZyjsMapper tGlutDcZyjsMapper;
    private TGlutDcBmxxMapper tGlutDcBmxxMapper;
    private ViewGlutJwKsqlcJgxxMapper viewGlutJwKsqlcJgxxMapper;
    private TGlutDcJssysjzlbMapper tGlutDcJssysjzlbMapper;
    private TGlutDcJwKsqlcJgxxMapper tGlutDcJwKsqlcJgxxMapper;
    private TGlutDcKcbJsMapper tGlutDcKcbJsMapper;
    //    private MqService mqService;
    private AsyncService asyncService;

    @Autowired
    public ViewServiceImpl(TGlutDcJhkczlbMapper tGlutDcJhkczlbMapper,
                           TGlutDcJsjbsjzlbMapper tGlutDcJsjbsjzlbMapper,
                           TGlutDcJxhbxxMapper tGlutDcJxhbxxMapper,
                           TGlutDcKcsjlbMapper tGlutDcKcsjlbMapper,
                           TGlutDcKcsjlbXxxsMapper tGlutDcKcsjlbXxxsMapper,
                           TGlutDcKsapsjlbMapper tGlutDcKsapsjlbMapper,
                           TGlutDcSkjsxxMapper tGlutDcSkjsxxMapper,
                           TGlutDcXksjlbMapper tGlutDcXksjlbMapper,
                           TGlutDcZtjhzlbMapper tGlutDcZtjhzlbMapper,
                           TGlutDcZyxxsjlbMapper tGlutDcZyxxsjlbMapper,
                           TGlutDcXjjbsjzlbMapper tGlutDcXjjbsjzlbMapper,
                           TGlutDcXsjbsjzlMapper tGlutDcXsjbsjzlMapper,
                           TGlutDcBjsjlbMapper tGlutDcBjsjlbMapper,
                           TGlutDcJiankaoMapper tGlutDcJiankaoMapper,
                           TGlutDcKsbjMapper tGlutDcKsbjMapper,
                           TGlutDcKsMapper tGlutDcKsMapper,
                           TGlutDcZyjsBjMapper tGlutDcZyjsBjMapper,
                           TGlutDcZyjsKaoshengMapper tGlutDcZyjsKaoshengMapper,
                           TGlutDcZyjsMapper tGlutDcZyjsMapper,
                           TGlutDcBmxxMapper tGlutDcBmxxMapper,
                           TGlutDcJssysjzlbMapper tGlutDcJssysjzlbMapper,
                           TGlutDcJwKsqlcJgxxMapper tGlutDcJwKsqlcJgxxMapper,
                           ViewGlutJwKsqlcJgxxMapper viewGlutJwKsqlcJgxxMapper,
                           TGlutDcKcbJsMapper tGlutDcKcbJsMapper,
//                           MqService mqService,
                           AsyncService asyncService) {
        this.tGlutDcJhkczlbMapper = tGlutDcJhkczlbMapper;
        this.tGlutDcJsjbsjzlbMapper = tGlutDcJsjbsjzlbMapper;
        this.tGlutDcJxhbxxMapper = tGlutDcJxhbxxMapper;
        this.tGlutDcKcsjlbMapper = tGlutDcKcsjlbMapper;
        this.tGlutDcKcsjlbXxxsMapper = tGlutDcKcsjlbXxxsMapper;
        this.tGlutDcKsapsjlbMapper = tGlutDcKsapsjlbMapper;
        this.tGlutDcSkjsxxMapper = tGlutDcSkjsxxMapper;
        this.tGlutDcXksjlbMapper = tGlutDcXksjlbMapper;
        this.tGlutDcZtjhzlbMapper = tGlutDcZtjhzlbMapper;
        this.tGlutDcZyxxsjlbMapper = tGlutDcZyxxsjlbMapper;
        this.tGlutDcXjjbsjzlbMapper = tGlutDcXjjbsjzlbMapper;
        this.tGlutDcXsjbsjzlMapper = tGlutDcXsjbsjzlMapper;
        this.tGlutDcBjsjlbMapper = tGlutDcBjsjlbMapper;
        this.tGlutDcJiankaoMapper = tGlutDcJiankaoMapper;
        this.tGlutDcKsbjMapper = tGlutDcKsbjMapper;
        this.tGlutDcKsMapper = tGlutDcKsMapper;
        this.tGlutDcZyjsBjMapper = tGlutDcZyjsBjMapper;
        this.tGlutDcZyjsKaoshengMapper = tGlutDcZyjsKaoshengMapper;
        this.tGlutDcZyjsMapper = tGlutDcZyjsMapper;
        this.tGlutDcBmxxMapper = tGlutDcBmxxMapper;
        this.tGlutDcJssysjzlbMapper = tGlutDcJssysjzlbMapper;
        this.tGlutDcJwKsqlcJgxxMapper = tGlutDcJwKsqlcJgxxMapper;
        this.viewGlutJwKsqlcJgxxMapper = viewGlutJwKsqlcJgxxMapper;
        this.tGlutDcKcbJsMapper = tGlutDcKcbJsMapper;
//        this.mqService = mqService;
        this.asyncService = asyncService;
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxJhkczlb() {
        Integer count = tGlutDcJhkczlbMapper.selectCount(new TGlutDcJhkczlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxJhkczlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxJhkczlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxJsjbsjzlb() {
        Integer count = tGlutDcJsjbsjzlbMapper.selectCount(new TGlutDcJsjbsjzlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxJsjbsjzlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxJsjbsjzlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxJxhbxx() {
        Integer count = tGlutDcJxhbxxMapper.selectCount(new TGlutDcJxhbxx());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxJxhbxx(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxJxhbxx(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxKcsjlb() {
        Integer count = tGlutDcKcsjlbMapper.selectCount(new TGlutDcKcsjlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxKcsjlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxKcsjlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxKcsjlbXxxs() {
        Integer count = tGlutDcKcsjlbXxxsMapper.selectCount(new TGlutDcKcsjlbXxxs());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxKcsjlbXxxs(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxKcsjlbXxxs(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxKsapsjlb() {
        Integer count = tGlutDcKsapsjlbMapper.selectCount(new TGlutDcKsapsjlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxKsapsjlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxKsapsjlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxSkjsxx() {
        Integer count = tGlutDcSkjsxxMapper.selectCount(new TGlutDcSkjsxx());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxSkjsxx(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxSkjsxx(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxXksjlb() {
        Integer count = tGlutDcXksjlbMapper.selectCount(new TGlutDcXksjlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxXksjlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxXksjlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxZtjhzlb() {
        Integer count = tGlutDcZtjhzlbMapper.selectCount(new TGlutDcZtjhzlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxZtjhzlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxZtjhzlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxjxZyxxsjlb() {
        Integer count = tGlutDcZyxxsjlbMapper.selectCount(new TGlutDcZyxxsjlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxjxZyxxsjlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxjxZyxxsjlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxxsXjjbsjzlb() {
        Integer count = tGlutDcXjjbsjzlbMapper.selectCount(new TGlutDcXjjbsjzlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxxsXjjbsjzlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxxsXjjbsjzlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxxsXsjbsjzl() {
        Integer count = tGlutDcXsjbsjzlMapper.selectCount(new TGlutDcXsjbsjzl());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxxsXsjbsjzl(i + 1, limit);
            }
        } else {
            asyncService.getViewGxxsXsjbsjzl(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewGxxxBjsjlb() {
        Integer count = tGlutDcBjsjlbMapper.selectCount(new TGlutDcBjsjlb());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewGxxxBjsjlb(i + 1, limit);
            }
        } else {
            asyncService.getViewGxxxBjsjlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsJiankao() {
        Integer count = tGlutDcJiankaoMapper.selectCount(new TGlutDcJiankao());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKsJiankao(i + 1, limit);
            }
        } else {
            asyncService.getViewKsJiankao(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsKsbj() {
        Integer count = tGlutDcKsbjMapper.selectCount(new TGlutDcKsbj());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKsKsbj(i + 1, limit);
            }
        } else {
            asyncService.getViewKsKsbj(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsKs() {
        Integer count = tGlutDcKsMapper.selectCount(new TGlutDcKs());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKsKs(i + 1, limit);
            }
        } else {
            asyncService.getViewKsKs(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsZyjsBj() {
        Integer count = tGlutDcZyjsBjMapper.selectCount(new TGlutDcZyjsBj());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKsZyjsBj(i + 1, limit);
            }
        } else {
            asyncService.getViewKsZyjsBj(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsZyjsKaosheng() {
        Integer count = tGlutDcZyjsKaoshengMapper.selectCount(new TGlutDcZyjsKaosheng());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.ksZyjsKaosheng(i + 1, limit);
            }
        } else {
            asyncService.ksZyjsKaosheng(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsZyjs() {
        Integer count = tGlutDcZyjsMapper.selectCount(new TGlutDcZyjs());
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKsZyjs(i + 1, limit);
            }
        } else {
            asyncService.getViewKsZyjs(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewBmxx() {
        Integer count = tGlutDcBmxxMapper.selectCount(new TGlutDcBmxx());
        log.info("部门信息条数:{}", count);
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewBmxx(i + 1, limit);
            }
        } else {
            asyncService.getViewBmxx(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewJssysjzlb() {
        Integer count = tGlutDcJssysjzlbMapper.selectCount(new TGlutDcJssysjzlb());
        log.info("教室信息条数:{}", count);
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewJssysjzlb(i + 1, limit);
            }
        } else {
            asyncService.getViewJssysjzlb(1, limit);
        }
    }

    @Async("glutExecutor")
    @Override
    public void getViewKsqlcJgxx() {
        Integer count = viewGlutJwKsqlcJgxxMapper.selectCount(new ViewGlutJwKsqlcJgxx());
        log.info("教工信息条数:{}", count);
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKsqlcJgxx(i + 1, limit);
            }
        } else {
            asyncService.getViewKsqlcJgxx(1, limit);
        }
    }

    @Override
    public void getViewKcbJs() {
        Integer count = tGlutDcKcbJsMapper.selectCount(new TGlutDcKcbJs());
        log.info("教工信息条数:{}", count);
        if (count > limit) {
            int ceil = new BigDecimal(count).divide(new BigDecimal(limit)).setScale(0, BigDecimal.ROUND_UP).intValue();
            for (int i = 0, length = ceil; length > i; i++) {
                asyncService.getViewKcbJs(i + 1, limit);
            }
        } else {
            asyncService.getViewKcbJs(1, limit);
        }
    }

    @Override
    public Integer getKsCount() {
        TGlutDcKs tGlutDcKs = new TGlutDcKs();
        tGlutDcKs.setXq("2020秋");
        return tGlutDcKsMapper.selectCount(new TGlutDcKs());
    }


}
